package com.sj.purchase.modules.cost.repository.order;

import com.sj.purchase.modules.cost.domain.WarehouseEnum;
import com.sj.purchase.modules.cost.domain.order.AdjustOrder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * Created by 宋开宗 on 2017/7/27 0027.
 */
public interface StockAdjustRepository extends JpaRepository<AdjustOrder, String> {

    List<AdjustOrder> findByCreateDateBetween(Date start, Date end);

    Page<AdjustOrder> findByCreateDateBetween(Date start, Date end, Pageable pageable);

    @Query("select a.skuNo,SUM (a.adjustedQty) from AdjustOrder a where a.warehouseEnum = ?1 and a.createDate between ?2 and ?3 and a.skuNo in ?4 group by a.skuNo")
    List<Object[]> findSkuAndNum(WarehouseEnum warehouseEnum, Date start, Date end, List<String> skuNos);
}
